//https://leetcode.cn/problems/diameter-of-binary-tree/

class Solution {
public:
    int res=0;
    int diameterOfBinaryTree(TreeNode* root) {
        if(root == nullptr) return 0;
        dfs(root);
        return res;
    }
    int dfs(TreeNode* root){
        if(root ==nullptr) return 0;
        int left_heght=dfs(root->left);
        int right_heght=dfs(root->right);
        res=std::max(left_heght+right_heght,res);
        return std::max(left_heght,right_heght)+1;
    }
};